#!/bin/bash
set -euo pipefail

ROOT_DIR=$(cd "$(dirname "$0")" && pwd)

if [ $# -eq 0 ]; then
	echo "please input the openssl source dir"
	exit 1
fi

OPENSSL_SOURCE_DIR=$1

rm -rf ${OPENSSL_SOURCE_DIR}/output_static
rm -rf ${OPENSSL_SOURCE_DIR}/output

cd ${OPENSSL_SOURCE_DIR}

OPENSSL_CONFIGURE_OPTS=(
	linux-x86_64
	--debug
	no-asm
	no-deprecated
	no-legacy
	no-tests
	no-docs
	no-shared
)
# static openssl bin
./Configure "${OPENSSL_CONFIGURE_OPTS[@]}" --prefix="${OPENSSL_SOURCE_DIR}/output_static"
make clean
make -j$(nproc) build_apps
make install

./Configure "${OPENSSL_CONFIGURE_OPTS[@]}" --prefix="${OPENSSL_SOURCE_DIR}/output"
make clean
make -j$(nproc)
make install
